package com.ruoyi.web.article.controller;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.article.domain.TrainArticleReadRecord;
import com.ruoyi.web.article.service.ITrainArticleReadRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章阅读数量Controller
 *
 * @author 范书铭
 * @date 2024-10-13
 */
@Api("文章阅读数量")
@RestController
@RequestMapping("/readRecord/readRecord")
public class TrainArticleReadRecordController extends BaseController {
    @Autowired
    private ITrainArticleReadRecordService trainArticleReadRecordService;

/**
 * 查询文章阅读数量列表
 */
@ApiOperation("查询文章阅读数量列表")
@PreAuthorize("@ss.hasPermi('readRecord:readRecord:list')")
@GetMapping("/list")
    public TableDataInfo list(TrainArticleReadRecord trainArticleReadRecord) {
        startPage();
        List<TrainArticleReadRecord> list = trainArticleReadRecordService.selectTrainArticleReadRecordList(trainArticleReadRecord);
        return getDataTable(list);
    }

    /**
     * 导出文章阅读数量列表
     */
    @ApiOperation("导出文章阅读数量列表")
    @PreAuthorize("@ss.hasPermi('readRecord:readRecord:export')")
    @Log(title = "文章阅读数量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainArticleReadRecord trainArticleReadRecord) {
        List<TrainArticleReadRecord> list = trainArticleReadRecordService.selectTrainArticleReadRecordList(trainArticleReadRecord);
        ExcelUtil<TrainArticleReadRecord> util = new ExcelUtil<TrainArticleReadRecord>(TrainArticleReadRecord. class);
        util.exportExcel(response, list, "文章阅读数量数据");
    }

    /**
     * 获取文章阅读数量详细信息
     */
    @ApiOperation("获取文章阅读数量详细信息")
    @PreAuthorize("@ss.hasPermi('readRecord:readRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(trainArticleReadRecordService.getById(id));
    }

    /**
     * 新增文章阅读数量
     */
    @ApiOperation("新增文章阅读数量")
    @PreAuthorize("@ss.hasPermi('readRecord:readRecord:add')")
    @Log(title = "文章阅读数量", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainArticleReadRecord trainArticleReadRecord) {
        return toAjax(trainArticleReadRecordService.save(trainArticleReadRecord));
    }

    /**
     * 修改文章阅读数量
     */
    @ApiOperation("修改文章阅读数量")
    @PreAuthorize("@ss.hasPermi('readRecord:readRecord:edit')")
    @Log(title = "文章阅读数量", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainArticleReadRecord trainArticleReadRecord) {
        return toAjax(trainArticleReadRecordService.save(trainArticleReadRecord));
    }

    /**
     * 删除文章阅读数量
     */
    @ApiOperation("删除文章阅读数量")
    @PreAuthorize("@ss.hasPermi('readRecord:readRecord:remove')")
    @Log(title = "文章阅读数量", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(trainArticleReadRecordService.removeByIds(Arrays.asList(ids)));
    }
}
